package com.vshop.service.alast.impl;

import com.alibaba.fastjson.JSON;
import com.vshop.config.dto.ResultDataDto;
import com.vshop.config.dto.StringOutputConstant;
import com.vshop.entity.agatewaytobeijing.querydevice.beijing.response.QueryDeviceData;
import com.vshop.entity.agatewaytobeijing.querydevice.beijing.response.ResponseQueryDevice;
import com.vshop.entity.agatewaytobeijing.querypartnercode.response.ResponseQueryPartnerByDeviceId;
import com.vshop.entity.alast.common.*;
import com.vshop.entity.alast.homepage.request.RequestUnifiedHomePage;
import com.vshop.entity.alast.homepage.response.PageDisplay;
import com.vshop.entity.alast.single.querydata.response.ResponseQueryData;
import com.vshop.entity.alast.single.serviceplan.response.ResponsePartnerServicePlan;
import com.vshop.entity.alast.single.serviceplan.response.ResponseSingleServicePlanPage;
import com.vshop.entity.alast.single.serviceplan.response.ResponseSpecAndPrice;
import com.vshop.entity.alast.single.verify.request.RequestSingleVerify;
import com.vshop.entity.alast.single.verify.response.ResponseSingleVerify;
import com.vshop.entity.requestinterface.Constant;
import com.vshop.mapper.alast.LogicProcessesMapper;
import com.vshop.service.PartnerInfoService;
import com.vshop.service.agatewaytobeijing.GatewayToBeijingService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.util.TextUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

/**
 * 所有的业务逻辑辅助处理类
 *
 * @author lm
 * @date 2020/8/26 15:25
 */

@Component
@Slf4j
public class LogicAssistService {

    @Autowired
    PartnerInfoService partnerService;
    @Resource
    private LogicProcessesMapper logicMapper;
    @Autowired
    GatewayToBeijingService toBeijingService;

    /**
     * 统一处理一下partnerCode，terminal，mark这三个参数
     * <p>
     * 原本需要判断partnerCode是不是以P或者p开头的来判断有效性;partnerCode不是以P或者p开头的渠道码组合；后来引入3.0的企业之后渠道编码不仅仅有P开头的了，就取消这个验证
     * boolean bp = StringUtils.isNotBlank(partnerCode) && partnerCode.startsWith("P") || partnerCode.startsWith("p");
     * if (!bp) {
     * log.info("partnerCode不是以P或者p开头的渠道码组合，值：" + partnerCode);
     * return invalidPartnerCode;
     * }
     *
     * @param terminal
     * @param mark
     * @return
     */
    public String unifiedHandling(String terminal, String mark, String invalidTerminal, String invalidMark) {
        boolean b = StringUtils.isNotBlank(terminal) && (StringOutputConstant.CODE_ZERO.equals(terminal) || StringOutputConstant.CODE_ONE.equals(terminal));
        if (b) {
            boolean b0 = StringUtils.isNotBlank(mark) && (StringOutputConstant.CODE_ZERO.equals(mark) || StringOutputConstant.CODE_ONE.equals(mark));
            if (b0) {
                return "SUCCESS";
            } else {
                //mark:卡片归属标识：0-归属领科（当为此值时卡片需要通过领科企业卡片有效性的验证）；1-不归属领科（当为此值时卡片不需要通过领科企业卡片有效性的验证）；默认标识传0（归属领科），如果打开H5时携带此参数以实际为准
                log.info("mark是除了0-归属领科；1-不归属领科以外的值：" + mark);
                return invalidMark;
            }
        } else {
            //terminal是除了0-移动终端；1-pc以外的值
            log.info("terminal是除了0-移动终端；1-pc以外的值：" + terminal);
            return invalidTerminal;
        }
    }

    /**
     * 单卡验证响应公共方法
     *
     * @param configList
     * @param deviceCode
     * @return
     */

    public ResponseSingleVerify responseSingleVerify(List<PartnerConfigContent> configList, String deviceCode, String languageCode) {

        ResponseSingleVerify response = null;
        //遍历方案：
        for (PartnerConfigContent config : configList) {
            //这边判断下请求的语言是不是在方案语言中
            Integer c = logicMapper.queryLanguageCodeOrNot(config.getPartnerCode(), config.getConfigType(), config.getPlanCode(), languageCode);

            //拿到方案标识去查询当前企业此方案对应的语言配置
            List<PartnerConfigLang> langList = logicMapper.queryLangType(config.getPartnerCode(), config.getConfigType(), config.getPlanCode());

            List<PageDisplay> displayList = new ArrayList<>();
            //遍历页面语言内容
            for (PartnerConfigLang t : langList) {
                PageDisplay display = new PageDisplay();
                display.setLanguageName(setLanguageName(t.getLanguageCode()));
                display.setLanguageCode(t.getLanguageCode());
                display.setLanguagePriority(t.getLanguagePriority());
                display.setWelcomeLang(t.getWelcomeLang());
                display.setPopupContent(t.getPopupContent());
                displayList.add(display);
            }

            //查到东西装载返回
            response = new ResponseSingleVerify();
            //语言是当前企业能够匹配上的一种语言
            if (c >= 1) {
                response.setMatchCode("1");
            } else {
                response.setMatchCode("0");
            }
            response.setPartnerCode(config.getPartnerCode());
            response.setDeviceCode(deviceCode);
            response.setPlanType(config.getConfigType());
            response.setPcBgimg(config.getPcBgimg());
            response.setPhBgimg(config.getPhBgimg());
            response.setLinkURL(config.getLinkURL());
            response.setPageDisplay(displayList);
        }
        return response;
    }

    /**
     * 公共方法：
     * 确定到底给这个企业匹配什么语言的套餐
     *
     * @param partnerCode
     * @param languageCode
     * @return
     */

    public String queryLanguageType(String partnerCode, String languageCode) {

        //走这边标识卡片没有过期，不管查询到的渠道编码是不是跟请求上来的一致，我们都用新的渠道编码去做覆盖然后继续去查询当前企业是否具有正在使用的某种方案
        List<PartnerConfigContent> configList = logicMapper.queryPlan(partnerCode);
        if (null == configList || configList.isEmpty()) {
            return "";
        }

        //遍历方案确定搜索套餐的语言:
        String languageType = "";
        for (PartnerConfigContent config : configList) {
            //拿到方案标识去查询当前企业此方案对应的语言配置
            List<PartnerConfigLang> langList = logicMapper.queryLangType(partnerCode, config.getConfigType(), config.getPlanCode());
            if (null == langList || langList.isEmpty()) {
                return "";
            }
            //这边判断下请求的语言是不是在方案语言中
            Integer c = logicMapper.queryLanguageCodeOrNot(partnerCode, config.getConfigType(), config.getPlanCode(), languageCode);
            if (c > 0) {
                //说明携带的语言跟企业的方案语言刚好能对上
                languageType = languageCode;
            } else {

                //外部携带的语言不是当前企业设定的语言范围
                for (PartnerConfigLang lang : langList) {
                    //拿到优先级为1的语言去匹配套餐
                    if (lang.getLanguagePriority().equalsIgnoreCase(StringOutputConstant.CODE_ONE)) {
                        languageType = lang.getLanguageCode();
                    }
                }
            }
        }
        return languageType;
    }


    /**
     * 归属领科的卡片匹配套餐的方法：
     * <p>
     * 根据：
     * 索引判断取数据的数据表名称
     * 企业编号索引，企业编码，设备编号，语言类型，套餐适用标识
     * <p>
     * 查询套餐列表
     *
     * @param partnerIndex
     * @param partnerCode
     * @param deviceCode
     * @param languageType
     * @return
     */

    public List<PartnerServicePlan> queryServicePlanCode(Integer partnerIndex, String partnerCode, String deviceCode, String languageType, String tags) {

        //根据索引确定取数据的数据表：数据表的名称
        String tableName = "partner_device_packages_relation_t_" + partnerIndex + "";

        //去指定的数据表里面根据条件取套餐数据
        return logicMapper.queryServicePlanList(tableName, partnerCode, deviceCode, languageType, tags);
    }

    /**
     * 公共方法：
     * 将获取到的套餐列表，
     * 先去匹配规格和价格，
     * 然后加载封装返回
     *
     * @param planList
     * @param partnerCode
     * @param type        '0'-multipleServicePlanPage请求（屏蔽掉autoRenewal='1'的套餐）；'1'-singleServicePlanPage请求（所有的套餐适用于单卡模式）
     * @return
     */

    public ResultDataDto responseServicePlan(List<PartnerServicePlan> planList, String partnerCode, String type) {
        //装配准备返回
        List<ResponsePartnerServicePlan> servicePlanList = new ArrayList<>();
        ResponsePartnerServicePlan plan = null;

        for (PartnerServicePlan pl : planList) {
            //1,取出套餐编码去匹配规格和价格
            List<PartnerServicePlanSpecPrice> priceList = logicMapper.querySpecPrice(pl.getPartnerCode(), pl.getPackageCode(), pl.getServicePlanCode(), type);

            //2,遍历规格和价格
            List<ResponseSpecAndPrice> specAndPriceList = new ArrayList<>();
            ResponseSpecAndPrice price = null;

            for (PartnerServicePlanSpecPrice pr : priceList) {
                //看看当前套餐需不需要特殊的价格展示
                Integer count = logicMapper.specialPriceHandle(pr.getPartnerCode(), pr.getPackageCode());
                price = new ResponseSpecAndPrice();
                //这边看看价格需不需要特殊处理
                if (count > 0) {
                    price.setCurrency("EUR");
                    price.setCurrencySymbol("€");
                } else {
                    price.setCurrency("USD");
                    price.setCurrencySymbol("$");
                }
                price.setOrderPeriod(pr.getSpecifications());
                price.setAutoRenewal(pr.getAutoRenewal());

                if (StringOutputConstant.CODE_ZERO.equals(pr.getPackageType()) || StringOutputConstant.CODE_ONE.equals(pr.getPackageType()) ||
                        StringOutputConstant.CODE_TWO.equals(pr.getPackageType()) || StringOutputConstant.CODE_FIVE.equals(pr.getPackageType())) {
                    price.setSpecifications(pr.getSpecifications());
                } else if (StringOutputConstant.CODE_THREE.equals(pr.getPackageType())) {
                    price.setSpecifications(String.valueOf(Integer.parseInt(pr.getSpecifications()) * 3));
                } else if (StringOutputConstant.CODE_FOUR.equals(pr.getPackageType())) {
                    price.setSpecifications(String.valueOf(Integer.parseInt(pr.getSpecifications()) * 6));
                } else {
                    price.setSpecifications(pr.getSpecifications());
                }

                price.setPackageType(pr.getPackageType());
                price.setDiscountPriceUSD(pr.getDiscountPriceUSD());
                price.setDiscountPriceCNY(pr.getDiscountPriceCNY());
                //这里的意思是：1，存在原价字段。2，当原价高于打折价的时候才会有原价和save字段返回。
                // 3，原本字段没有值的时候会返回saveCNY=null,使用配置jackson:default-property-inclusion: non_null屏蔽掉这些字段
                if (StringUtils.isNotBlank(pr.getOriginalPriceUSD()) && StringUtils.isNotBlank(pr.getOriginalPriceCNY()) &&
                        0 < (Double.parseDouble(pr.getOriginalPriceCNY()) - Double.parseDouble(pr.getDiscountPriceCNY())) &&
                        0 < (Double.parseDouble(pr.getOriginalPriceUSD()) - Double.parseDouble(pr.getDiscountPriceUSD()))) {
                    price.setOriginalPriceUSD(pr.getOriginalPriceUSD());
                    price.setOriginalPriceCNY(pr.getOriginalPriceCNY());
                    price.setSaveCNY(String.format("%.2f", (Double.parseDouble(pr.getOriginalPriceCNY()) - Double.parseDouble(pr.getDiscountPriceCNY()))));
                    price.setSaveUSD(String.format("%.2f", (Double.parseDouble(pr.getOriginalPriceUSD()) - Double.parseDouble(pr.getDiscountPriceUSD()))));
                }
                specAndPriceList.add(price);
            }
            //有规格和价格才需要返回对应的套餐信息
            if (!priceList.isEmpty()) {
                //2,取出套餐相关参数做返回
                plan = new ResponsePartnerServicePlan();
                plan.setPackageCode(pl.getPackageCode());
                plan.setMinOrderPeriod(pl.getMinOrderPeriod());
                plan.setServicePlanCode(pl.getServicePlanCode());
                plan.setServicePlanShowName(pl.getServicePlanShowName());
                plan.setServicePlanShortDesc(pl.getServicePlanShortDesc());
                plan.setServicePlanDetailsDesc(pl.getServicePlanDetailsDesc());
                plan.setLanguageCode(pl.getLanguageType());
                plan.setSpecAndPriceList(specAndPriceList);
                servicePlanList.add(plan);
            }
        }

        //返回
        ResponseSingleServicePlanPage response = new ResponseSingleServicePlanPage();
        response.setPartnerCode(partnerCode);
        response.setPlanList(servicePlanList);
        log.info("【匹配套餐列表】成功响应：" + JSON.toJSONString(response));
        return ResultDataDto.addOperationSuccess().setData(response);
    }

    /**
     * 不归属领科的卡片，匹配固定服务费套餐
     * <p>
     * 根据：企业编码，语言类型，套餐适用标识
     *
     * @param partnerCode
     * @param languageType
     * @param tags
     * @param area
     * @return
     */

    public List<PartnerServicePlan> queryServiceFeePlan(String partnerCode, String languageType, String tags, String area) {
        return logicMapper.queryServiceFeePlan(partnerCode, languageType, tags, area);
    }

    /**
     * 公共方法：
     * iccId-设备识别码有效性的验证
     *
     * @param deviceCode
     * @return
     */

    public String validationDeviceCode(String deviceCode, LangMultipleErrorMsg msg) {

        //判断卡片是否有效：1，是不是领科的卡，2，是不是不在“废旧回收期”和“内部库存期”内。
        ResponseQueryPartnerByDeviceId partner = toBeijingService.queryPartnerCode(deviceCode.trim());

        if (null != partner) {
            boolean b1 = StringUtils.isNotBlank(partner.getCode()) && StringUtils.isNotBlank(partner.getMessage()) && Constant.RET_CODE_0000.equals(partner.getCode()) && null != partner.getData();

            if (!b1) {
                log.info("【iccId验证】查询渠道编码返回有误：" + partner.getMessage());
                return msg.getResPartnerException();
            }

            //返回看似没有问题，但是返回的渠道编码却不合法或者0（领之飞自己）
            if (StringUtils.isBlank(partner.getData().getPartner_code()) || StringOutputConstant.CODE_ZERO.equals(partner.getData().getPartner_code())) {
                log.info("【iccId验证】系领之飞卡提示:无效卡片");
                return msg.getInvalidCard();
            }

            //如果以上步骤都没有问题证明至少是领科出的卡没有错，我们继续用获得的企业编码去做更多的查询
            String secret = partnerService.getSecretByPartnerCode(partner.getData().getPartner_code());
            if (StringUtils.isBlank(secret)) {
                log.info("【iccId验证】" + partner.getData().getPartner_code() + ";当前企业secret有误请联系管理员！");
                return msg.getInvalidSecret();
            }

            //如果以上都还是没有问题，现在查询下设备的状态，为了屏蔽掉在内部库存期或废弃回收期内的卡片，不让这类卡片订购套餐。
            ResponseQueryDevice device = toBeijingService.queryDevice(deviceCode.trim(), partner.getData().getPartner_code(), secret);
            if (null != device) {
                boolean b2 = StringUtils.isNotBlank(device.getCode()) && StringUtils.isNotBlank(device.getMessage()) && Constant.RET_CODE_0000.equals(device.getCode()) && null != device.getData();
                if (!b2) {
                    log.info("【iccId验证】查询设备信息返回有误：" + device.getMessage());
                    return msg.getResPartnerException();
                }

                //如果查询结果返回还是没有问题，那么我们现在来屏蔽掉在内部库存期或废弃回收期内的卡片，不让这类卡片订购套餐。
                QueryDeviceData tr = device.getData();
                //如果卡片在内部库存期或废弃回收期内内，表明卡片过期了，不允许Top-up
                boolean b3 = StringUtils.isBlank(tr.getLifecycle()) || "null".equalsIgnoreCase(tr.getLifecycle()) ||
                        (StringUtils.isNotBlank(tr.getLifecycle()) && (tr.getLifecycle().equals(StringOutputConstant.CODE_FOUR) || tr.getLifecycle().equals(StringOutputConstant.CODE_FIVE)));
                if (b3) {
                    log.info("【iccId验证】SIM卡已过期");
                    return msg.getExpiredSimCard();
                }

                //走这边标识卡片没有过期，不管查询到的渠道编码是不是跟请求上来的一致，我们都用新的渠道编码去做覆盖然后继续去查询当前企业是否具有正在使用的某种方案
                List<PartnerConfigContent> configList = logicMapper.queryPlanOrder(partner.getData().getPartner_code());
                if (null == configList || configList.isEmpty()) {
                    log.info("【iccId验证】当前归属企业无正在使用的直接订购方案");
                    return msg.getNotInUsePlan();
                }
            } else {
                log.info("【iccId验证】查询设备信息程序有误");
                return msg.getResException();
            }
        } else {
            log.info("【iccId验证】查询渠道编码程序有误");
            return msg.getResException();
        }
        //卡片验证成功了
        return "SUCCESS";
    }

    /**
     * 入库访问登录记录
     *
     * @param request
     */
    public Integer storageDeviceLoginRecord(RequestSingleVerify request) {

        PartnerAccessDeviceLoginRecord record = new PartnerAccessDeviceLoginRecord();
        record.setTradeTime(request.getTradeTime());
        record.setVersion(request.getVersion());
        record.setTerminal(request.getTerminal());
        record.setMark(request.getMark());
        record.setLanguageCode(request.getLanguageCode());
        record.setPartnerCode(request.getPartnerCode());
        record.setDeviceCode(request.getDeviceCode());
        return logicMapper.storageDeviceLoginRecord(record);
    }

    /**
     * 入库默认首页的访问记录
     *
     * @param request
     */

    public Integer storageHomePageRecord(RequestUnifiedHomePage request) {
        PartnerAccessHomePageRecord record = new PartnerAccessHomePageRecord();
        record.setTradeTime(request.getTradeTime());
        record.setVersion(request.getVersion());
        record.setTerminal(request.getTerminal());
        record.setMark(request.getMark());
        record.setUrl(request.getUrl());
        record.setPartnerCode(request.getPartnerCode());
        record.setLocation("0");
        return logicMapper.storageHomePageRecord(record);
    }

    /**
     * 入库点击"Multiple"的访问记录
     *
     * @param request
     */

    public Integer storageMultipleRecord(RequestUnifiedHomePage request) {
        PartnerAccessMultipleRecord record = new PartnerAccessMultipleRecord();
        record.setTradeTime(request.getTradeTime());
        record.setVersion(request.getVersion());
        record.setTerminal(request.getTerminal());
        record.setMark(request.getMark());
        record.setUrl(request.getUrl());
        record.setPartnerCode(request.getPartnerCode());
        record.setLocation("1");
        return logicMapper.storageMultipleRecord(record);
    }

    /**
     * 根据语言code设置name
     *
     * @param languageCode
     * @return
     */
    public String setLanguageName(String languageCode) {

        if (StringUtils.isNotBlank(languageCode)) {

            if (StringOutputConstant.CODE_ZERO.equals(languageCode)) {
                return ("中文");
            } else if (StringOutputConstant.CODE_ONE.equals(languageCode)) {
                return ("English");
            } else if (StringOutputConstant.CODE_TWO.equals(languageCode)) {
                return ("español");
            } else if (StringOutputConstant.CODE_THREE.equals(languageCode)) {
                return ("En français");
            } else if (StringOutputConstant.CODE_FOUR.equals(languageCode)) {
                return ("português");
            } else if (StringOutputConstant.CODE_FIVE.equals(languageCode)) {
                return ("हिंदीName");
            } else if (StringOutputConstant.CODE_SIX.equals(languageCode)) {
                return ("Deutsch");
            } else if (StringOutputConstant.CODE_SEVEN.equals(languageCode)) {
                return ("日本語");
            } else if (StringOutputConstant.CODE_EIGHT.equals(languageCode)) {
                return ("한국어");
            } else if (StringOutputConstant.CODE_NINE.equals(languageCode)) {
                return ("العربية");
            } else if (StringOutputConstant.CODE_TEN.equals(languageCode)) {
                return ("台湾繁中");
            } else if (StringOutputConstant.CODE_ELEVEN.equals(languageCode)) {
                return ("港体繁中");
            } else if (StringOutputConstant.CODE_TWELVE.equals(languageCode)) {
                return ("Русский язык");
            } else {
                return ("其他");
            }
        }
        return "";
    }

    /**
     * 判断数组中是否有重复的值
     * 由于hashSet实现了set接口，所以它不允许集合中有重复的值，在调用add方法时，如果插入了重复值，会返回false
     *
     * @param array
     * @return
     */
    public boolean checkIsRepeat(String[] array) {
        HashSet<String> hashSet = new HashSet<>();
        for (int i = 0; i < array.length; i++) {
            hashSet.add(array[i]);
        }
        if (hashSet.size() == array.length) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 标准化输出orderPeriod
     * 按照packageType的值来判断
     * 特殊处理季度，半年，4个月，18个月，2年
     *
     * @param packageType
     * @param orderPeriod
     * @return
     */
    public String setOrderPeriod(String packageType, String orderPeriod) {
        String result = "";
        //原始：周期+单位
        if (StringOutputConstant.CODE_ZERO.equals(packageType) ||
                StringOutputConstant.CODE_ONE.equals(packageType) ||
                StringOutputConstant.CODE_TWO.equals(packageType) ||
                StringOutputConstant.CODE_FIVE.equals(packageType)) {
            result = orderPeriod;
        } //特殊处理季度套餐：周期*3+单位（月）
        else if (StringOutputConstant.CODE_THREE.equals(packageType)) {
            result = String.valueOf(Integer.parseInt(orderPeriod) * 3);
        }  //特殊处理半年套餐：周期*6+单位（月）
        else if (StringOutputConstant.CODE_FOUR.equals(packageType)) {
            result = String.valueOf(Integer.parseInt(orderPeriod) * 6);
        } //特殊处理4个月套餐：周期*4+单位（月）
        else if (StringOutputConstant.CODE_SIX.equals(packageType)) {
            result = String.valueOf(Integer.parseInt(orderPeriod) * 4);
        } //特殊处理18个月套餐：周期*18+单位（月）
        else if (StringOutputConstant.CODE_SEVEN.equals(packageType)) {
            result = String.valueOf(Integer.parseInt(orderPeriod) * 18);
        } //特殊处理2年套餐：周期*2+单位（年）
        else if (StringOutputConstant.CODE_EIGHT.equals(packageType)) {
            result = String.valueOf(Integer.parseInt(orderPeriod) * 2);
        } //原始：周期+单位
        else {
            result = orderPeriod;
        }
        return result;
    }

    /**
     * 根据 languageCode 获取多语言错误提示信息
     *
     * @param languageCode
     * @return
     */

    public LangMultipleErrorMsg getLangMultipleErrorMsg(String languageCode) {
        return logicMapper.getLangMultipleErrorMsg(languageCode);
    }

    /**
     * 异常情况下查询流量方案返回
     *
     * @param showContent
     * @param partnerCode
     * @return
     */
    public ResponseQueryData responseShowContent(String showContent, String partnerCode) {
        ResponseQueryData response = null;

        //根据数据库里面的字段分别去匹配并且返回
        if (StringUtils.isNotBlank(showContent)) {
            response = new ResponseQueryData();
            //截取获得字符串数组
            String[] strArray = showContent.split(",");
            for (int i = 0; i < strArray.length; i++) {
                if (strArray[i].equals("servicePlanShowName")) {
                    response.setServicePlanShowName("-");
                } else if (strArray[i].equals("activeDate")) {
                    response.setActiveDate("-");
                } else if (strArray[i].equals("expireDate")) {
                    response.setExpireDate("-");
                } else if (strArray[i].equals("dataTotal")) {
                    response.setDataTotal("-");
                } else if (strArray[i].equals("dataBalance")) {
                    response.setDataBalance("-");
                }
                response.setPackageType("-");
            }
        } else {
            //数据库没有查询到或者数组else的情况都走下面的路：
            response = new ResponseQueryData();
            response.setServicePlanShowName("-");
            response.setActiveDate("-");
            response.setExpireDate("-");
            response.setDataTotal("-");
            response.setDataBalance("-");
            response.setPackageType("-");
        }
        response.setPartnerCode(partnerCode);
        return response;
    }

    /**
     * 默认套餐统一输出
     *
     * @param languageCode
     * @return
     */
    public String setServicePlanShowName(String languageCode) {
        if (StringOutputConstant.CODE_ZERO.equals(languageCode)) {
            return "卡片默认套餐";
        } else if (StringOutputConstant.CODE_ONE.equals(languageCode)) {
            return "Default Service Plan";
        } else if (StringOutputConstant.CODE_TWO.equals(languageCode)) {
            return "Paquete predeterminado de tarjetas";
        } else if (StringOutputConstant.CODE_THREE.equals(languageCode)) {
            return "Paquets de cartes par défaut";
        } else if (StringOutputConstant.CODE_FOUR.equals(languageCode)) {
            return "Pacote predefinido de cartões";
        } else if (StringOutputConstant.CODE_FIVE.equals(languageCode)) {
            return "कार्ड डिफ़ॉल्ट पैकेज";
        } else if (StringOutputConstant.CODE_SIX.equals(languageCode)) {
            return "Kartenstandardpaket";
        } else if (StringOutputConstant.CODE_SEVEN.equals(languageCode)) {
            return "カードのデフォルトパッケージ";
        } else if (StringOutputConstant.CODE_EIGHT.equals(languageCode)) {
            return "카드 기본 패키지";
        } else if (StringOutputConstant.CODE_NINE.equals(languageCode)) {
            return "حزمة البطاقة الافتراضية";
        } else if (StringOutputConstant.CODE_TEN.equals(languageCode)) {
            return "卡片默認套餐";
        } else if (StringOutputConstant.CODE_ELEVEN.equals(languageCode)) {
            return "卡片默認套餐";
        } else if (StringOutputConstant.CODE_TWELVE.equals(languageCode)) {
            return "Kartenstandardpaket";
        } else {
            return "Default Service Plan";
        }
    }

    /**
     * 保留中间的空格，过滤字符串前后的空格
     *
     * @param str
     * @return
     */
    public String saveStrInnerSpace(String str) {
        if (TextUtils.isEmpty(str)) {
            return str;
        }
        str = str.trim();
        while (str.startsWith(" ")) {
            str = str.substring(1, str.length()).trim();
        }
        while (str.endsWith(" ")) {
            str = str.substring(0, str.length() - 1).trim();
        }
        return str;
    }

    /**
     * 查询partnerCode这个企业是否已经升级为3.0
     *
     * @param partnerCode
     * @return
     */
    public Integer queryUpgradedOrNot(String partnerCode) {
        return logicMapper.queryUpgradedOrNot(partnerCode);
    }
}
